package cn.tedu.custom.client;

import cn.tedu.luban.demo.cart.api.HelloService;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.Socket;

public class RpcProxy implements HelloService {
    @Override
    public String sayHi(String name) {
        try{
            Socket socket=new Socket("localhost",20000);
            //是我想要调用的接口的参数 sayHi(name)
            //使用socket的outputstream包装字符串的二进制序列化数据
            OutputStream outputStream = socket.getOutputStream();
            DataOutputStream dos=new DataOutputStream(outputStream);
            //序列化操作
            dos.writeUTF(name);
            //需要返回值
            DataInputStream dis=new DataInputStream(socket.getInputStream());
            String result = dis.readUTF();
            return result;
            //System.out.println("客户端提供参数 并且接收到对方的返回值:"+result);
        }catch (Exception e){

        }
        return null;
    }
}
